package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.Home3_add1Bean;

import java.util.List;

/**
 * Created by Administrator on 2016/9/12 0012.
 */
public class Home3_add1Adapter extends BaseAdapter {
    private Context context;
    private List<Home3_add1Bean> home3List1;

    public Home3_add1Adapter(Context context, List<Home3_add1Bean> home3List1) {
        this.context = context;
        this.home3List1 = home3List1;
    }

    @Override
    public int getCount() {
        return home3List1.size();
    }

    @Override
    public Object getItem(int position) {
        return home3List1.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Home3ViewHolder viewHolder = new Home3ViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.home3_item, null);
            viewHolder.iv_img_item = (ImageView) convertView.findViewById(R.id.iv_img_item);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            viewHolder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (Home3ViewHolder) convertView.getTag();
        }

        System.out.println(home3List1.get(position).getImg() + "==========");

        if ("0".equals(home3List1.get(position).getImg())) {
            viewHolder.iv_img_item.setVisibility(View.GONE);
        } else {
            viewHolder.iv_img_item.setVisibility(View.VISIBLE);
            viewHolder.iv_img_item.setImageResource(Integer.parseInt(home3List1.get(position).getImg()));
        }

//        viewHolder.iv_img_item.setImageResource(Integer.parseInt(home3List1.get(position).getImg()));
        viewHolder.tv_title.setText(home3List1.get(position).getTitle());
        viewHolder.tv_time.setText(home3List1.get(position).getTime());
        viewHolder.tv_content.setText(home3List1.get(position).getContent());

        return convertView;
    }

    class Home3ViewHolder {
        ImageView iv_img_item;
        TextView tv_title;
        TextView tv_time;
        TextView tv_content;
    }
}
